using System;
using System.Drawing;

using Game.World;
using Game.Output;

namespace Game.Input
{
	public static class CNavigation
	{
		public const int SCROLL_SPEED = 8; // pixels per frame
		
		public enum Direction
		{
			NORTH		= 0,
			EAST		= 1,
			SOUTH		= 2,
			WEST		= 3,			
			NORTH_EAST	= 4,
			SOUTH_EAST	= 5,
			SOUTH_WEST	= 6,
			NORTH_WEST	= 7
		}
		
		private static Point m_scrollPosition;
		
		public static void Initialize()
		{
			CConsole.ReportClassInit(System.Reflection.MethodInfo.GetCurrentMethod().DeclaringType.Name);
		}
		
		public static void Scroll(Point offset)
		{
			m_scrollPosition = new Point(
				m_scrollPosition.X + offset.X,
				m_scrollPosition.Y + offset.Y
			);	
		}
		
		public static void Scroll(Direction direction)
		{
			switch (direction)
			{
				// standard directions
				case Direction.NORTH :
					m_scrollPosition.Y = m_scrollPosition.Y + SCROLL_SPEED;
					break;
					
				case Direction.EAST :
					m_scrollPosition.X = m_scrollPosition.X + SCROLL_SPEED;
					break;
					
				case Direction.SOUTH :
					m_scrollPosition.Y = m_scrollPosition.Y - SCROLL_SPEED;
					break;
					
				case Direction.WEST :
					m_scrollPosition.X = m_scrollPosition.X - SCROLL_SPEED;
					break;
					
				// combined directions
				case Direction.NORTH_EAST :
					Scroll(Direction.NORTH);
					Scroll(Direction.EAST);
					break;
					
				case Direction.SOUTH_EAST :
					Scroll(Direction.SOUTH);
					Scroll(Direction.EAST);
					break;
					
				case Direction.SOUTH_WEST :
					Scroll(Direction.SOUTH);
					Scroll(Direction.WEST);
					break;
					
				case Direction.NORTH_WEST :
					Scroll(Direction.NORTH);
					Scroll(Direction.WEST);
					break;
			}
		}

		public static bool PointInArea(Point point, Rectangle rect)
		{
			if (
				point.X >= rect.Left && point.X <= rect.Right &&
				point.Y >= rect.Top && point.Y <= rect.Bottom
			)
				return true;
			else
				return false;
		}
		
		public static bool IsInsideTerrain(Point tileCoords, ref CTerrain p_terrain)
		{
			if (
				tileCoords.X < 0 || tileCoords.X >= p_terrain.Surface.Width ||
				tileCoords.Y < 0 || tileCoords.Y >= p_terrain.Surface.Height
			)
				return false;
			else
				return true;
		}
		
	}
}
